import React from 'react';
import { obj_int, obj_str, loc, ck_int, useKForm, KDlg, KInput } from 'sui';

const DlgTask = (props) => {
    const form = useKForm(props.data);

    const ck = {
        dnum : v => {
            const e = ck_int(v);
            if (e) {
                return e;
            }

            const tmp = parseInt(v, 10);
            const count = obj_int(props.data, "dnum");

            if (tmp > count) {
                return loc("l_707");
            }

            return null;
        },
    };

    const getTitle = () => {
        if (props.title) {
            return props.title;
        }

        return loc("l_852");
    };

    return (
        <KDlg {...props} title={getTitle()} ck={ck} form={form}>
            <div className="text-base mb-2">{loc("l_177")}<span className="ml-8">{obj_str(props.data, "sn")}</span></div>
            <div className="text-base mb-2">{loc("l_127")}<span className="ml-8">{obj_str(props.data, "dnum")}</span></div>
            <KInput label={loc("l_127")} form={form} name="dnum"/>
        </KDlg>
    );
};

export {DlgTask};
